<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <title>编辑收集人员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <style type="text/css">

    </style>
    <script type="text/css">
        body{text-align:center;}
    </script>
</head>

<body>
    <div style="position:absolute;top:20%;left:5%">
        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">员工号</label>
                    <div class="layui-input-inline">
                        <input id="no" type="text" name="no" required lay-verify="required" placeholder="请输入员工号" autocomplete="off" class="layui-input">
                        <input id="id" type="text" name="id" style="display:none">
                    </div>
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <span class="layui-form-label" id="name"></span>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">物业公司</label>
                    <input id="areaname" type="text" style="display:none">
                    <div class="layui-input-inline">
                        <select id="select" lay-verify="required" class="layui-input" name="area" lay-search>
								<option value=""></option>
							</select>
                    </div>
                    <label class="layui-form-label">原智能卡号</label>
                    <div class="layui-input-inline">
                        <span class="layui-form-label" id="nfcname"></span>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">暂停智能卡</label>
                    <div class="layui-input-inline">
                        <input type="checkbox" id="btn1" name="nfcdel" value="1" title="是">
                    </div>
                    <label class="layui-form-label">重绑智能卡</label>
                    <div class="layui-input-inline">
                        <select name="nfc1" id="nfc1" class="layui-input" lay-search>
								<option value=""></option>
							</select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea id="memo" name="memo" placeholder="请输入备注" autocomplete="off" class="layui-textarea"></textarea>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn " lay-submit lay-filter="edit">保存</button>
                    <button class="layui-btn layui-btn-primary" id="close">取消</button>
                </div>
            </div>
        </div>
    </div>
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'user'], function() {
            var $ = layui.$,
                setter = layui.setter,
                admin = layui.admin,
                form = layui.form,
                router = layui.router(),
                search = router.search;
            form.render();
            //提交
            layui.use('laydate', function() {
                var laydate = layui.laydate;
                //执行一个laydate实例
                laydate.render({
                    elem: '#bdate' //指定元素
                });
            });
            form.on('submit(edit)', function(obj) {
                admin.req({
                    url: "../../../Employees/saveedit",
                    type: "post",
                    datatype: "json",
                    data: obj.field,
                    success: function(res) {
                        if (res.data == "ok") {
                            layer.msg('编辑成功', {
                                offset: 'auto',
                                icon: 1,
                                time: 1500,
                                end: function() {
                                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                    parent.layer.close(index); // 关闭layer
                                    window.parent.location.reload(); //刷新父页面
                                }
                            })
                        } else if (res.data == '无权限') {
                            layer.msg('没有权限，编辑失败', {
                                offset: 'auto',
                                icon: 2,
                                time: 1000,
                                end: function() {
                                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                    parent.layer.close(index);
                                }
                            })
                        } else {
                            layer.msg('编辑失败', {
                                offset: 'auto',
                                icon: 2,
                                time: 1000
                            })
                        }
                    },
                    error: function(res) {
                        layer.msg('编辑失败', {
                            offset: 'auto',
                            icon: 2,
                            time: 1000
                        })
                    }
                })
            });
            $.ajax({
                url: "../../../Area/getareaex",
                type: "post",
                datatype: "json",
                success: function(res) {
                    $.each(res.data, function(index) {
                        var id = res.data[index].id;
                        var name = res.data[index].areaname;
                        $("#select").append("<option value='" + id + "'>" + name + "</option>")
                    })
                    var are = $("#areaname").val();
                    var Vselect = $("#select option")
                    for (var i = 0; i < Vselect.length; i++) {
                        var b = Vselect[i].text;
                        if (are == b) {
                            $("#select option").eq(i).attr('selected', true);
                            form.render();
                        }
                    }
                }
            });
            $.ajax({
                url: "../../../Employees/selectnfc1",
                type: "post",
                datatype: "json",
                success: function(res) {
                    $.each(res.data, function(index) {
                        var id = res.data[index].id;
                        var name = res.data[index].nfcname;
                        $("#nfc1").append("<option value='" + id + "'>" + name + "</option>")
                    })
                    form.render();

                }
            });
            $("#close").on("click", function() {
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index); // 关闭layer
            });
        });
    </script>

</body>

</html>